package com.kvin.alipaylib.util;

import android.app.Activity;

import com.alipay.sdk.app.AuthTask;
import com.alipay.sdk.app.PayTask;

import java.util.Map;

import com.kvin.alipaylib.AuthResult;
import com.kvin.alipaylib.PayResult;

/**
 * Created by Kvin on 2017/6/12.
 */
public class AliUtils {

    public static final String RESULT_SUCCESS = "9000";
    public static final String RESPONSE_SUCCESS = "200";

    private Activity act;

    private AliUtils(Activity act){
        this.act=act;
    }

    public static AliUtils getInstance(Activity act){
        return new AliUtils(act);
    }

    /**
     * ali pay,placed in child thread
     */
    public  Map<String, String> aliPay(String orderInfo) {
        PayTask task = new PayTask(act);
        return task.payV2(orderInfo, true);
    }

    /**
     * ali auth
     */
    public Map<String, String> aliAuth(String authInfo) {
        AuthTask task = new AuthTask(act);
        return task.authV2(authInfo, true);
    }

    /**
     * get pay result
     */
    public static PayResult getPayResult(Map<String, String> result) {
        return new PayResult(result);
    }

    /**
     * get pay result
     */
    public static AuthResult getAuthResult(Map<String, String> result) {
        return new AuthResult(result, true);
    }
    public static AuthResult getAuthResult(Map<String, String> result,boolean removeBrackets) {
        return new AuthResult(result, removeBrackets);
    }
}